import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDEquipmentColor {
	/**品质id*/
	id,
	/**随机属性条数*/
	randomAttributeNum,
	/**品质名称*/
	name,

	/**枚举数量*/
	EnumCount
}



export class CDEquipmentColor{
	/**品质id*/
	public id: number;
	/**随机属性条数*/
	public randomAttributeNum: number[];
	/**品质名称*/
	public name: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDEquipmentColor.id: return this.id;
			case E_CDEquipmentColor.randomAttributeNum: return this.randomAttributeNum;
			case E_CDEquipmentColor.name: return this.name;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDEquipmentColor.id: this.id = v; break;
			case E_CDEquipmentColor.randomAttributeNum: this.randomAttributeNum = v; break;
			case E_CDEquipmentColor.name: this.name = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDEquipmentColor> = new HashMap<number, CDEquipmentColor>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDEquipmentColor[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDEquipmentColor();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].randomAttributeNum = [];
			const attrArray = list[i].randomAttributeNum;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDEquipmentColor{
		return this.datas ? this.datas.get(id) : null;
	}
}
